package myTCPTest;


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        // 创建服务器端的Socket对象
        ServerSocket ss = new ServerSocket(12345);

        // 侦听客户端，得到一个Socket对象
        Socket accept = ss.accept();

        // 获取输入流，读数据并打印
        InputStream in = accept.getInputStream();
        byte[] bys = new byte[1024];
        int len = in.read(bys);
        System.out.println("服务端：" + new String(bys, 0, len));

        // 给客户端反馈
        OutputStream os = accept.getOutputStream();
        os.write("true".getBytes());

        // 释放资源
        ss.close();
    }
}
